class Director
{
    private transitionTime;
    private effectType;
    private _sceneList;
    public constructor()
    {
        this.transitionTime = 500;
        this.effectType = 0;
        this._sceneList = [];
    }
    static instance: Director;
    static getInstance()
    {
        if(null == Director.instance)
        {
            Director.instance = new Director;
        }
        return Director.instance;
    }
    public rootView;
    public initialize(a)
    {
        this.rootView = a;
    }
    public runningScene;
    public runWithScene(a)
    {
        this._sceneList.push(a);
        this.runningScene = a;
        this.runScene();
    }
    public replacedScene;
    public replaceScene(a,b = 1)
    {
        this.effectType = b;
        if(0 < this._sceneList.length)
        {
            this.replacedScene = this._sceneList.pop();
        }
        this.runWithScene(a);
    }
    public pushScene(a,b = 1)
    {
        this.effectType = b;
        var c = this._sceneList.length;
        if(0 < c)
        {
            this.replacedScene = this._sceneList[c - 1];
        }
        this.runWithScene(a);
    }
    public popScene(a = 1)
    {
        this.effectType = a;
        a = this._sceneList.length;
        if(2 <= a)
        {
            this.replacedScene = this._sceneList.pop();
            this.runWithScene(this._sceneList[a - 2]);
        }
    }
    public fadeMask;
    public runScene()
    {
        var a = this;
        if(null != this.replacedScene)
        {
            switch(this.effectType)
            {
                case 0:
                    this.rootView.addChildAt(this.runningScene,0);
                    EffectUtils.rightSlidingIn(this.runningScene,this.transitionTime).call(this.onEnterTransitionDidFinish,this);
                    EffectUtils.leftSlidingOut(this.replacedScene,this.transitionTime);
                    break;
                case 1:
                    if(null == this.fadeMask)
                    {
                        this.fadeMask = new egret.Sprite;
                        this.fadeMask.graphics.beginFill(0);
                        this.fadeMask.graphics.drawRect(0,0,this.runningScene.width,this.runningScene.height);
                        this.fadeMask.graphics.endFill();
                        this.fadeMask.alpha = 0;
                    };
                    this.rootView.addChild(this.fadeMask);
                    EffectUtils.fadeIn(this.fadeMask,this.transitionTime).call(function()
                    {
                        a.rootView.removeChild(a.replacedScene);
                        a.rootView.addChildAt(a.runningScene,0);
                        EffectUtils.fadeOut(a.fadeMask,a.transitionTime).call(a.onEnterTransitionDidFinish,a)
                    },this);
            }
            this.runningScene.onEnter();
            this.runningScene.onEnterTransitionDidStart(!0);
            this.replacedScene.onEnterTransitionDidStart(!1)
        }
        else
        {
            this.rootView.addChildAt(this.runningScene,0);
        }
    }
    public onEnterTransitionDidFinish()
    {
        this.runningScene.onEnterTransitionDidFinish(!0);
        this.replacedScene.onEnterTransitionDidFinish(!1);
        this.replacedScene.onExit();
        if(this.replacedScene && this.replacedScene.parent)
        {
            this.rootView.removeChild(this.replacedScene);
        }
        if(this.fadeMask && this.fadeMask.parent)
        {
            this.rootView.removeChild(this.fadeMask);
        }
        this.replacedScene = null;
    }
}